package org.javaweb.cms_web.controller;

import org.javaweb.cms_web.model.Article;
import org.javaweb.cms_web.model.ArticleDTO;
import org.javaweb.cms_web.model.Team;
import org.javaweb.cms_web.service.AchievementService;
import org.javaweb.cms_web.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.javaweb.cms_web.service.ArticleManagementService;
import org.springframework.web.bind.annotation.*;

import java.util.List;


import java.util.List;

@Controller
public class DashboardController {

    @Autowired
    private ArticleManagementService articleManagementService;

    @Autowired
    private AchievementService achievementService;

    @Autowired
    private TeamService teamService;

    @GetMapping("/dashboard")
    public String loadDashboard(Model model) {
        // 查询团队
        Team team = teamService.getTeamById(1);
        model.addAttribute("team", team);

        // 查询文章
        List<ArticleDTO> articles = articleManagementService.getArticlesByTeam(1);
        model.addAttribute("articles", articles);

        // 查询成果
        model.addAttribute("books", achievementService.getAchievementsByTeam(1, 0));
        model.addAttribute("patents", achievementService.getAchievementsByTeam(1, 1));
        model.addAttribute("softwareAchievements", achievementService.getAchievementsByTeam(1, 2));
        model.addAttribute("products", achievementService.getAchievementsByTeam(1, 3));

        return "normalUserDashboard";
    }
}


